<template>
	<view class="page page-block">
		<cl-toast ref="toast"></cl-toast>
		<view class="head-wrapper"></view>
		<view class="head-img-wrapper">
			<view class="img-wrapper">
				<image class="head-img" :src="photo"></image>
			</view>
		</view>
		<view class="userInfo-wrapper">
			<view v-if="name.trim() != ''" class="userInfo-block" @longpress="copy(0)">
				<text class="userInfo-text">昵称：</text>
				<text selectable="true" class="userInfo-info">{{name}}</text>
			</view>
			<view v-if="qq.trim() != ''" class="userInfo-block" @longpress="copy(0)">
				<text class="userInfo-text">QQ：</text>
				<text selectable="true" class="userInfo-info">{{qq}}</text>
			</view>
			<view v-if="phone.trim() != ''" class="userInfo-block" @longpress="copy(1)">
				<text class="userInfo-text">电话：</text>
				<text selectable="true" class="userInfo-info">{{phone}}</text>
			</view>
			<view v-if="email.trim() != ''" class="userInfo-block" @longpress="copy(2)">
				<text class="userInfo-text">邮箱：</text>
				<text selectable="true" class="userInfo-info">{{email}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name: "",
				photo: "",
				qq: "",
				phone: "",
				email: ""
			}
		},
		methods: {
			copy(type) {
				// #ifndef H5
				let data;
				if (type == 0) {
					data = this.qq;
				} else if (type == 1) {
					data = this.phone;
				} else if (type == 2) {
					data = this.email;
				} else {
					return;
				}
				uni.setClipboardData({
					data: data,
					complete: () => {
						this.$refs["toast"].open({
							message: "复制成功",
							position: "bottom"
						})
					},
					fail: () => {
						this.$refs["toast"].open({
							message: "复制失败",
							position: "bottom"
						})
					}
				})
				// #endif
			},
			selectUserInfo(uid) {
				this.$common.request(this.$serverUrl + "user/" + uid, null, "GET", this.successCallback);
			},
			successCallback(res) {
				if (res.data.statusCode == "200") {
					if (res.data.msg == "ok") {
						this.name = res.data.data[0].name;
						this.photo = res.data.data[0].photo == null ? "/static/icon/head-icon.jpg":this.$common.photoUrlFormat(res.data.data[0].photo);
						this.qq = res.data.data[0].qq;
						this.phone = res.data.data[0].phone;
						this.email = res.data.data[0].email;
					} else {
						this.$common.showModal(res.data.msg, false);
					}
				}
			}
		},
		onLoad(param) {
			if (param.uid == this.$common.user.uid) {
				this.name = this.$common.user.name;
				this.photo = this.$common.user.photo;
				this.qq = this.$common.user.qq;
				this.phone = this.$common.user.phone;
				this.email = this.$common.user.email;
			} else {
				this.selectUserInfo(param.uid);
			}
		}
	}
</script>

<style>
	.head-wrapper {
		height: 96rpx;
		background-color: #2196F3;
	}

	.head-img-wrapper {
		height: 230rpx;
		background-image: linear-gradient(#2196F3, #2196F3, #FFFFFF, #FFFFFF);
		display: flex;
		justify-content: center;
	}

	.img-wrapper {
		width: 200rpx;
		height: 200rpx;
		padding: 15rpx;
		background-color: #FFFFFF;
		border-radius: 50%;
		display: flex;
		justify-content: center;
	}

	.head-img {
		width: 200rpx;
		height: 200rpx;
		border-radius: 50%;
		border: 1rpx solid #888888;
		align-self: center;
	}

	.userInfo-block {
		display: flex;
		flex-direction: column;
		margin: 30rpx 110rpx;
		padding: 20rpx;
		border: 2rpx solid #e5e5e5;
		border-radius: 28rpx;
	}

	.userInfo-text {
		display: flex;
		font-weight: bold;
		font-size: 20px;
	}

	.userInfo-text:before {
		content: "";
		border-radius: 32rpx;
		min-width: 20rpx;
		max-height: 38rpx;
		background-color: #2196F3;
		margin-top: 18rpx;
		margin-right: 15rpx;
	}

	.userInfo-info {
		margin-top: 10rpx;
		font-size: 18px;
	}
</style>
